<?php
namespace control;
//管理员后台 - 抄送我的
class notifyMeClass extends adIndexClass
{
    private const page = 'notifyMe'; # 权限
    private const table = 'audit'; # 数据表
    private const title = '抄送我的';

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            default:
                $tr = [
                    'orderNo'          => [
                        'name'  => L('person.table.dan_ju_bian_hao'),
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'flowName'  => [
                        'name'  => L('person.table.lcmc'),
                        'width' => 200,
                    ],
                    'commitTime'         => [
                        'name'  => L('person.table.tjsj'),
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'applicant'          => [
                        'name'  => L('person.table.shen_qing_ren'),
                        'width' => 200,
                    ],
                    'applicantDepartment'          => [
                        'name'  => L('person.table.sqrbm'),
                        'width' => 200,
                    ],
                    'workFlow'          => [
                        'name'  => L('person.table.dqjd'),
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'approver'          => [
                        'name'  => L('person.table.dqspr'),
                        'width' => 150,
                    ],
                    'commitTimePrevious'          => [
                        'name'  => L('person.table.sjdtjsj'),
                        'width' => 150,
                        'sort' => 1,
                    ]
                ];
        }
        return $tr;
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    L('person.table.ckzt')   => checkbox(['name' => 'see', 'value' => ['是'=>'已查看', '否'=>'未查看'], 'checked' => ['否']]),
                ],
                [
                    L('person.table.dan_ju_bian_hao') => text(array("name" => "orderNo")),
                    L('person.table.lcmc')   => text(array("name" => "flowName")),
                    L('person.table.sqbm')   => text(array("name" => "applicantDepartment")),
                ],
                [
                    L('person.table.shen_qing_ren')   => text(array("name" => "applicant")),
                    L('person.table.commitDate') => text(["name" => "commitTime", 'laydate' => [ 'range' => '~']]),
                    L('person.table.dqjd') => select(["name" => "workFlow", 'option' => ['审核中', '已通过']]),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /*成本表列表-查询条件*/
    public function home()
    {
        $html = $this->homeOptions(false);
        //控件
        $button = '';
        //返回
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    /*成本表列表-查询结果*/
    public function homeSearch()
    {
        if ($this->post('see')) {
            $where = " id in (SELECT typeId FROM `message` WHERE `stid` = '" . self::$stid . "' AND `see` IN (" . whereIn($this->post('see')) . ") ) ";
        } else {
            $where = " id in (SELECT typeId FROM `message` WHERE `stid` = '" . self::$stid . "' ) ";
        }
        $equal = [
            'workFlow' => $this->post('workFlow'),
        ];
        $like = [
            'orderNo' => $this->post('orderNo'),
            'flowName' => $this->post('flowName'),
            'applicantDepartment' => $this->post('applicantDepartment'),
            'applicant' => $this->post('applicant'),
        ];
        if ($this->post('commitTime')) {
            $where .= $this->timeComparison($this->post('commitTime'), field: 'commitTime');
        }
        $where .= search([
            "=" => $equal,
            "like" => $like,
        ]);
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'commitTime',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(),
        ));
        //获取查询结果
        $page = $this->page([
            "table" => self::table,
            "where" => $where,
            "order" => $orderBy['orderBy'],

        ]);
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("listForm", "id")
        );
        //获取记录
        foreach ($page['array'] as $array) {
            $url = root . "control/adIndex.html?cla=" . $array['targetCla'] . "&fun=" . $array['targetFun'];
            $dominate = [
                "box" => [
                    "name" => "id",
                    "value" => $array['id']
                ],
                "detail" => [
                    "title" => L('person.table.spxq'),
                    "click" => "newIframe('" . L('person.table.spxq') . "','" . $url . "&id=" . $array['targetId'] . "')"
                ],
            ];
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case 'commitTimePrevious':
                        $row[] = self::null($array['commitTimePrevious']);
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = '';
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . $li . "</form>" . $page['button'] . clear;
        return json_encode($json, 320);
    }
}
